

#pragma once
#include <rviz_common/panel.hpp>
#include <rviz_common/config.hpp>
#include "rviz_custom_plugins/panels/ui_flyzone_panel.h"
#include "rviz_custom_plugins/viewmodels/point_group_model.h"
#include "rviz_custom_plugins/utils/interactive_marker_thread.h"
#include <std_msgs/msg/color_rgba.hpp>
#include <geometry_msgs/msg/point.hpp>
#include <QVector3D>
#include <QColor>


using rviz_common::Config;
using rviz_custom_plugins::utils::InteractiveMarkerThread;
using rviz_custom_plugins::viewmodels::PointGroupModel;


namespace rviz_custom_plugins {


namespace panels {


class FlyzonePanel : public rviz_common::Panel
{
    Q_OBJECT

public:
    explicit FlyzonePanel(QWidget *parent = nullptr);

    void load(const Config& config) override;

private:

    inline static const QString L1_ROW = "l1_row";
    inline static const QString L2_ROW = "l2_row";

    Ui::flyzonePanel* ui{ nullptr };
    PointGroupModel* treeModel;
    std::shared_ptr<InteractiveMarkerThread> markerThread;

    // 空间类型: 1.飞行空间  2.禁飞空间
    int zoneType;
    // 顶点和多边形的颜色
    QColor markerColor;
    // 多边形顶点的初始位置
    geometry_msgs::msg::Point initialPosition;

    void removeBoxButtonClicked();
    void addBoxButtonClicked();

    // void addPointButtonClicked();
	// void insertPointButtonClicked();
	// void removePointButtonClicked();

    void getCurrentIndex(int& l1Row, int& l2Row);

    void addGroup(geometry_msgs::msg::Point minPoint, geometry_msgs::msg::Point maxPoint);
    void removeGroup(int l1Row);

private slots:
    void handleMarkerFeedback(InteractiveMarkerServer::FeedbackConstSharedPtr feedback);
    void handlerPointsReorder(int l1Row, int l2Row, std::list<InteractiveMarker>& markers);
    void handleActiveStatusChanged(bool active);

    void handleProjectLoaded(QSharedPointer<QVariantMap> projectData);
    void handleProjectSaved(QSharedPointer<QVariantMap> projectData);
    void handleProjectClosed(QSharedPointer<QVariantMap> projectData);


    // void handlerBoxesReorder(int l1Row, std::list<std::list<InteractiveMarker>>& markersList);
};


}


}
